//
//  BSStatusRetweetView.swift
//  mySwiftWeibo
//
//  Created by apple on 16/7/31.
//  Copyright © 2016年 itcast沈庆伟. All rights reserved.
//

import UIKit

///被转发微博view
class BSStatusRetweetView: UIView {

    ///被转发微博模型,可能没有
    var retweeted_status: BSStatus? {
        didSet{
            //拿到被转发微博模型,设置内容
            if retweeted_status == nil {
                retweetContentLabel.text = "没有被转发微博"
            }else{
                let name = retweeted_status?.user?.screen_name ?? "没有名称"
                let text = retweeted_status?.text ?? "没有微博内容"
                let content = "@ \(name): \(text))"
                
                retweetContentLabel.text = content
            }
            
            //设置配图
            retweetPictureView.imageURLs = retweeted_status?.storePictureURLs
            
            retweetPictureView.snp_makeConstraints { (make) -> Void in
                var margin: CGFloat = 0
                if retweeted_status?.storePictureURLs != nil && retweeted_status?.storePictureURLs?.count > 0{
                    margin = CellMargin
                }
                
                make.top.equalTo(retweetContentLabel.snp_bottom).offset(margin)
            }
        }
    }
    
    /*****************************/
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor(white: 239, alpha: 0)
        
        setupUI()
    }
    /*****************************/
    ///UI
    private func setupUI() {
        self.addSubview(retweetContentLabel)
        self.addSubview(retweetPictureView)
        
        //约束
        retweetContentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(self).offset(CellMargin)
        }
        
        retweetPictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(CellMargin)
            make.top.equalTo(retweetContentLabel.snp_bottom).offset(CellMargin)
            make.size.equalTo(CGSize(width: 300, height: 300))
        }
        
        //底部约束
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(retweetPictureView).offset(CellMargin)
        }
    }
    
    //MARK: - 懒加载
    private lazy var retweetContentLabel: UILabel={
       let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: CellFontSize)
        
        //行宽度
        label.preferredMaxLayoutWidth = UIScreen.width() - 2 * CellMargin
        label.numberOfLines = 0
        
        label.sizeToFit()
        
        return label
    }()
    
    //配图
    private lazy var retweetPictureView: BSStatusPictureView = BSStatusPictureView()
    
}
